<template>
  <div>
    <div :class="isBuyAll?'content mb80':'content'">
      <!-- 导航栏 -->
      <!-- <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>商品</el-breadcrumb-item>
          </el-breadcrumb> -->

      <el-carousel trigger="click" class="uni-margin-wrap" height="150px" v-if="adlist.length>0">
        <el-carousel-item v-for="item,i in adlist" :key="i">
          <img class="img" style="height:150px; width:100%" :src="item.resources" />
        </el-carousel-item>
      </el-carousel>
      <!-- 通告栏 -->
      <div class="notice-bar">
        <div class="notice-bar-title">最新<span style="color:rgb(51,153,254)">成交记录</span></div>
        <marquee>
          购买了<span style='color:#fe6a05'>魔兽燃烧的远征</span>游戏币<span style='color:#fe6a05'>20000金币=510</span>
        </marquee>
      </div>
      <!-- 交易 -->
      <div class="transaction">
        <!-- tab切换 -->
        <div class="scroll-div_H">
          <!-- <div class="scroll-div-item_H" :class="navIndex ==1 ? 'activite' : ''" @click="checkIndex(1)">
            角色交易
          </div>
          <div class="scroll-div-item_H" :class="navIndex ==2 ? 'activite' : ''" @click="checkIndex(2)">
            装备交易
          </div> -->
          <div class="scroll-div-item_H" :class="navIndex == 3? 'activite' : ''" @click="checkIndex(3)">
            游戏币交易
          </div>
        </div>
        <div class="content">

          <!-- <div class="swiper_item" v-show="navIndex==1">
         
            <div class="search">
              <div class="uni-form-item">
                <span>姓名：</span>
                <el-input v-model="roleSearch.name" size="mini" placeholder="请输入角色姓名"></el-input>
              </div>
              <div class="uni-form-item">
                <span>角色等级：</span>
                <el-input v-model="roleSearch.level01" size="mini" placeholder="请输入等级"></el-input>
                <div class="line"></div>
                <el-input v-model="roleSearch.level02" size="mini" placeholder="请输入等级"></el-input>
              </div>
              <div class="uni-form-item">
                <span>所在区服：</span>
                <el-select v-model="roleSearch.area" size="mini" placeholder="请选择区服">
                  <el-option v-for="item in district" :key="item.id" :label="item.value" :value="item.id">
                  </el-option>
                </el-select>
              </div>
              <div class="uni-form-item">
                <span>价格：</span>
                <el-input v-model="roleSearch.pic01" size="mini" placeholder="请输入最低价"></el-input>
                <div class="line"></div>
                <el-input v-model="roleSearch.pic02" size="mini" placeholder="请输入最高价"></el-input>
              </div>
              <el-button class="form-search" type="danger" size="mini">搜索</el-button>
              <el-button class="form-search" type="danger" plain size="mini">重置</el-button>
            </div>

            <el-table :header-cell-style="{background:'#F3F4F7',color:'#555'}" :data="tableData" @selection-change="roleSelectionChange" style="width: 100%">
              <el-table-column type="selection" width="55">
              </el-table-column>
              <el-table-column label="默认排序">
                <template slot-scope="scope">
                  <img style="width:50px;height:50px" :src="scope.row.img" />
                </template>
              </el-table-column>
              <el-table-column prop="name" label="姓名" sortable>
              </el-table-column>
              <el-table-column prop="roleRanking" label="角色等级" sortable>
              </el-table-column>
              <el-table-column prop="districtServing" label="所在区服" sortable>
              </el-table-column>
              <el-table-column prop="price" label="价格" sortable>
              </el-table-column>
              <el-table-column>
                <template slot-scope="scope">
                  <el-button class="seedetails" @click="toggle(scope.row)">查看详情</el-button>
                </template>
              </el-table-column>

            </el-table>
            <el-pagination background layout="prev, pager, next,sizes,total" :total='total' @current-change='current_change' @size-change='size_change' style="text-align: center;  margin-top: 60px;" :page-sizes="[10, 50, 100, 1000]">
            </el-pagination>
          </div>
          <div class="swiper_item" v-show="navIndex==2">
  
            <div class="search">
              <div class="uni-form-item">
                <span>道具名称：</span>
                <el-input v-model="equipSearch.name" size="mini" placeholder="请输入道具名称"></el-input>
              </div>
              <div class="uni-form-item">
                <span>所在区服：</span>
                <el-select v-model="equipSearch.area" size="mini" placeholder="请选择区服">
                  <el-option v-for="item in district" :key="item.id" :label="item.value" :value="item.id">
                  </el-option>
                </el-select>
              </div>
              <div class="uni-form-item">
                <span>价格：</span>
                <el-input v-model="equipSearch.pic01" size="mini" placeholder="请输入最低价"></el-input>
                <div class="line"></div>
                <el-input v-model="equipSearch.pic02" size="mini" placeholder="请输入最高价"></el-input>
              </div>
              <el-button class="form-search" type="danger" size="mini">搜索</el-button>
              <el-button class="form-search" type="danger" plain size="mini">重置</el-button>
            </div>

            <el-table :header-cell-style="{background:'#F3F4F7',color:'#555'}" :data="tableData" @selection-change="equipSelectionChange" style="width: 100%">
              <el-table-column type="selection" width="55">
              </el-table-column>
              <el-table-column label="默认排序">
                <template slot-scope="scope">
                  <img style="width:50px;height:50px" :src="scope.row.img" />
                </template>
              </el-table-column>
              <el-table-column prop="name" label="道具名称" sortable>
              </el-table-column>
              <el-table-column prop="roleRanking" label="出售人" sortable>
              </el-table-column>
              <el-table-column prop="districtServing" label="所在区服" sortable>
              </el-table-column>
              <el-table-column prop="price" label="价格" sortable>
              </el-table-column>
              <el-table-column prop="price" label="数量" sortable>
              </el-table-column>
              <el-table-column prop="price" label="售价" sortable>
              </el-table-column>
              <el-table-column>
                <template slot-scope="scope">
                  <el-button class="seedetails" @click="bindPurchase(scope.row)">购买</el-button>
                </template>
              </el-table-column>

            </el-table>
            <el-pagination background layout="prev, pager, next,sizes,total" :total='total' @current-change='current_change' @size-change='size_change' style="text-align: center;  margin-top: 60px;" :page-sizes="[10, 50, 100, 1000]">
            </el-pagination>
          </div> -->

          <div class="swiper_item" v-show="navIndex==3">
            <!-- 搜索 -->
            <div class="search">
              <div class="uni-form-item">
                <span>货币类型：</span>
                <el-select v-model="gameSearch.name" size="mini" placeholder="请选择货币类型">
                  <el-option v-for="item in currency" :key="item.id" :label="item.value" :value="item.id">
                  </el-option>
                </el-select>
              </div>
              <div class="uni-form-item">
                <span>所在区服：</span>
                <el-select v-model="gameSearch.area" size="mini" placeholder="请选择区服">
                  <el-option v-for="item in district" :key="item.m2Id" :label="item.serverName" :value="item.m2Id">
                  </el-option>
                </el-select>
              </div>
              <!-- <div class="uni-form-item">
                <span>价格：</span>
                <el-input v-model="gameSearch.pic01" size="mini" placeholder="请输入最低价"></el-input>
                <div class="line"></div>
                <el-input v-model="gameSearch.pic02" size="mini" placeholder="请输入最高价"></el-input>
              </div> -->
              <el-button class="form-search" type="danger" :disabled="loading" @click="CurrencyList()" size="mini">搜索</el-button>
              <!-- <el-button class="form-search" type="danger" plain size="mini">重置</el-button> -->
            </div>
            <!-- 表格 -->
            <el-table :header-cell-style="{background:'#F3F4F7',color:'#555'}" v-loading="loading" :data="gametableData" @header-click="headerClic" @selection-change="gemaSelectionChange" style="width: 100%">
              <el-table-column type="selection" width="55">
              </el-table-column>
              <el-table-column label="默认排序" width="100px">
                <template>
                  <img width="32" height="32" src="../../assets/static/t-16.png" />
                </template>
              </el-table-column>
              <el-table-column prop="name" label="货币类型" sortable>
                <template slot-scope="scope">
                  {{ gameType(scope.row.currencyType)}}
                </template>
              </el-table-column>
              <el-table-column prop="humanName" label="出售人" sortable>
              </el-table-column>
              <el-table-column prop="serverName" label="所在区服" sortable>
              </el-table-column>
              <el-table-column prop="currencyAmount" label="数量" sortable>
              </el-table-column>
              <el-table-column prop="currencyPrice" label="售价" sortable>
              </el-table-column>
              <el-table-column prop="updateTime" label="时间" sortable>
                <template slot-scope="scope">
                  {{getDateTime(scope.row.updateTime)}}
                </template>
              </el-table-column>
              <el-table-column label="操作" width="100" align="center">
                <template slot-scope="scope">
                  <el-button class="seedetails" @click="bindPurchase(scope.row)">购买</el-button>
                </template>
              </el-table-column>

            </el-table>
            <el-pagination background layout="prev, pager, next,sizes,total" v-if="total>0" :total='total' @current-change='current_change' @size-change='size_change' style="text-align: center;  margin-top: 60px;" :page-sizes="[20, 50, 100, 1000]">
            </el-pagination>

          </div>

        </div>
        <!-- 详情 -->
        <el-dialog width="450px" center title="角色详情" :close-on-click-modal="false" :visible.sync="dialogTableVisible">
          <!-- 详情 -->
          <div class="trading">
            <!-- 标题 -->

            <!-- 1 -->
            <div class="trading-particulars">
              <div class="charactername">
                <div>名称</div>
                <span>零点忘忧怀旧服</span>
              </div>
              <div class="charactername">
                <div>职业</div>
                <span>零点忘忧怀旧服</span>
              </div>
              <div class="charactername">
                <div>角色等级</div>
                <span>111</span>
              </div>
            </div>
            <!-- 2 -->
            <div class="trading-particulars">
              <div class="role-information">
                <div class="information">
                  <span>角色经验：</span>
                  <span>100000</span>
                </div>
                <div class="information">
                  <span>角色游戏点：</span>
                  <span>怀旧二区</span>
                </div>
              </div>
              <div class="role-information">
                <div class="information">
                  <span>角色金币：</span>
                  <span>100000</span>
                </div>
                <div class="information">
                  <span>角色灵符：</span>
                  <span>怀旧二区</span>
                </div>
              </div>
              <div class="role-information">
                <div class="information">
                  <span>角色元宝：</span>
                  <span>100000</span>
                </div>
                <div class="information">
                  <span>角色声望：</span>
                  <span>怀旧二区</span>
                </div>
              </div>
            </div>
            <!-- 3 -->
            <div class="trading-particulars">
              <div class="role-information">
                <div class="information">
                  <span>角色武器：</span>
                  <span>100000</span>
                </div>
                <div class="information">
                  <span>角色项链：</span>
                  <span>怀旧二区</span>
                </div>
              </div>
              <div class="role-information">
                <div class="information">
                  <span>角色衣服：</span>
                  <span>100000</span>
                </div>
                <div class="information">
                  <span>角色勋章：</span>
                  <span>怀旧二区</span>
                </div>
              </div>
              <div class="role-information">
                <div class="information">
                  <span>角色头盔：</span>
                  <span>100000</span>
                </div>
                <div class="information">
                  <span>角色腰带：</span>
                  <span>怀旧二区</span>
                </div>
              </div>
            </div>
            <!-- 4 -->
            <div class="trading-particulars last-particulars">
              <div class="role-information">
                <div class="information">
                  <span>角色手镯(左)：</span>
                  <span>100000</span>
                </div>
                <div class="information">
                  <span>角色戒指(左)：</span>
                  <span>怀旧二区</span>
                </div>
              </div>
              <div class="role-information">
                <div class="information">
                  <span>角色手镯(右)：</span>
                  <span>100000</span>
                </div>
                <div class="information">
                  <span>角色戒指(右)：</span>
                  <span>怀旧二区</span>
                </div>
              </div>
              <div class="role-information">
                <div class="information">
                  <span>角色靴子：</span>
                  <span>100000</span>
                </div>
              </div>
            </div>
            <!-- 按钮 -->
            <div class="tradingbuy">

              <div class="buynow" @click="bindPurchaseRole()" type="danger">立即购买</div>
              <div class="cancel" type="danger" @click="close()">取消</div>

            </div>
          </div>
        </el-dialog>
        <!-- {{ option }} -->

      </div>

    </div>
    <div class="deatail_good_pic" v-if="isBuyAll">
      <div class="deatail_good_pic_txt">
        已选商品<b>{{buyAllLength}}</b> 件
      </div>
      <div class="deatail_good_pic_but">
        合计:<b style="color: #e84a3c;font-size: 24px;">￥{{buyAllPic}}</b>

        <!-- <router-link tag="a" target="_blank" :to="{path:'./confirmBuy'}">
                    <el-button class="deatail_good_pic_but_button" @click="bindALLGood()" type="danger" >￥{{buyAllPic}}</el-button>
                </router-link> -->
        <el-button class="deatail_good_pic_but_button" @click="bindALLGood()" type="danger">立即购买</el-button>

      </div>
    </div>
  </div>
</template>

<script>
import api from '../../api/game'
export default {
  name: 'detail',
  data () {
    return {
      adlist: '',
      role_latergood: '', // 详情后购买临时数据
      role_good_list: '', // 角色商品
      equip_good_list: '', // 装备商品
      game_good_list: '', // 游戏币商品
      good_list: '', // 下单商品
      buyAllLength: 0,
      buyAllPic: 0,
      isBuyAll: false,
      current: 1,
      pageSize: 20,
      total: 0,
      dialogTableVisible: false,
      loading: false,
      option: '',
      scrollTop: 0,
      navIndex: 3,

      roleSearch: {
        // 角色搜索框
        name: '',
        level01: '',
        level02: '',
        area: '',
        pic02: '',
        pic01: ''
      },
      equipSearch: {
        // 装备搜索框
        name: '',
        area: '',
        pic01: '',
        pic02: ''
      },
      gameSearch: {
        // 游戏币搜索框
        name: '',
        area: '',
        pic01: '',
        pic02: ''
      },
      // 货币下拉框
      currency: [
        { id: 1, value: '金币' },
        { id: 2, value: '元宝' },
        { id: 3, value: '金刚石' },
        { id: 4, value: '灵符' },
        { id: 5, value: '游戏点' },
        { id: 6, value: '声望' },
        { id: 7, value: '荣誉点' }
      ],
      // 区服下拉框
      district: [],
      // 角色交易表格
      tableData: [],
      // 装备交易表格
      equiptableData: [],
      // 游戏币交易表格
      gametableData: []
    }
  },

  computed: {},
  mounted () {
    // localStorage.removeItem('good_list')
    // localStorage.removeItem('navIndex')
    this.init()
  },
  methods: {
    getDateTime (e) {
      var date = new Date(e)
      var y = date.getFullYear()
      var m = date.getMonth()
      var d = date.getDate()
      var tt = date.getTime()
      var hh = date.getHours()
      var mm = date.getMinutes()
      var ss = date.getSeconds()
      return y + '-' + m + '-' + d + '  ' + hh + ':' + mm + ':' + ss
    },
    current_change (e) {
      this.current = e
      this.CurrencyList()
    },
    size_change (e) {
      this.pageSize = e
      this.CurrencyList()
    },
    init () {
      const id = this.$route.query.id
      if (id == null) {
        return
      }
      this.$apis.gamedetails({ id: id }).then(res => {
        this.adlist = res.data.data.topList
      })
      this.GameAreaList(id)
    },
    GameAreaList (id) {
      // 货币分区下拉
      api.GameAreaList({ shopid: id }).then(res => {
        var data = res.data.data.areaList
        if (data) {
          this.district = data
          this.gameSearch.area = this.district[0].m2Id
          this.gameSearch.name = 1
          this.CurrencyList()
        }
      })
    },

    CurrencyList () {
      // 货币商品
      if (this.gameSearch.area == '' && this.gameSearch.name == '') {
        return
      }
      this.loading = true
      api
        .CurrencyList({
          M2Id: this.gameSearch.area,
          CurrencyType: this.gameSearch.name,
          Current: this.current,
          PageSize: this.pageSize
        })
        .then(res => {
          this.loading = false
          var data = res.data.data.currencyArray
          if (data) {
            this.gametableData = data
            this.total = res.data.data.total
          } else {
            this.gametableData = []
            this.total = 0
          }
        })
    },
    gameType (e) {
      if (e == 1) {
        return '金币'
      }
      if (e == 2) {
        return '元宝'
      }
      if (e == 3) {
        return '金刚石'
      }
      if (e == 4) {
        return '灵符'
      }
      if (e == 5) {
        return '游戏点'
      }
      if (e == 6) {
        return '声望'
      }
      if (e == 7) {
        return '荣誉点'
      }
    },

    checkIndex (index) {
      if (this.navIndex == index) {
        return
      }
      this.navIndex = index
      var e
      switch (index) {
        case 1:
          e = this.role_good_list
          break
        case 2:
          e = this.equip_good_list
          break
        case 3:
          e = this.game_good_list
          break
        default:
      }

      this.totalPrice(e)
    },

    gemaSelectionChange (e) {
      // 游戏勾选
      this.game_good_list = e
      this.totalPrice(e)
    },
    equipSelectionChange (e) {
      // 装备勾选
      this.equip_good_list = e
      this.totalPrice(e)
    },
    roleSelectionChange (e) {
      this.role_good_list = e
      this.totalPrice(e)
    },
    totalPrice (e) {
      // 底部总价计算
      this.buyAllLength = 0
      this.buyAllPic = 0
      if (e.length > 0) {
        this.isBuyAll = true
        this.buyAllLength = e.length
        e.map(item => {
          this.buyAllPic += Number(item.currencyPrice)
        })
        this.good_list = e
      } else {
        this.isBuyAll = false
      }
    },
    bindALLGood () {
      // 全部购买
      if (
        !localStorage.getItem('storage_key') &&
        !localStorage.getItem('token')
      ) {
        this.$message.error('请登录..')
        return
      }
      localStorage.setItem('good_list', JSON.stringify(this.good_list))
      localStorage.setItem('navIndex', this.navIndex)
      localStorage.setItem(
        'shop',
        JSON.stringify({
          ShopId: this.$route.query.id,
          M2Id: this.gameSearch.area
        })
      )
      this.$router.push({ path: './confirmBuy' })
    },
    bindPurchase (e) {
      // 立即购买
      if (
        !localStorage.getItem('storage_key') &&
        !localStorage.getItem('token')
      ) {
        this.$message.error('请登录..')
        return
      }
      localStorage.setItem('good_list', JSON.stringify([e]))
      localStorage.setItem('navIndex', this.navIndex)
      localStorage.setItem(
        'shop',
        JSON.stringify({
          ShopId: this.$route.query.id,
          M2Id: this.gameSearch.area
        })
      )
      this.$router.push({ path: './confirmBuy' })
    },
    bindPurchaseRole () {
      // 查看详情后购买
      if (
        !localStorage.getItem('storage_key') &&
        !localStorage.getItem('token')
      ) {
        this.$message.error('请登录..')
        return
      }
      localStorage.setItem('good_list', JSON.stringify(this.role_latergood))
      localStorage.setItem('navIndex', this.navIndex)
      localStorage.setItem(
        'shop',
        JSON.stringify({
          ShopId: this.$route.query.id,
          M2Id: this.gameSearch.area
        })
      )
      this.dialogTableVisible = false
      this.$router.push({ path: './confirmBuy' })
    },
    toggle (e) {
      // 查看详情弹出
      this.role_latergood = [e]
      this.dialogTableVisible = true
    },
    close () {
      this.dialogTableVisible = false
    },

    headerClic (item) {
      // console.log((item.label = 65465))
    }
  }
}
</script>

<style lang="less" scoped>
.swiper {
  width: 100%;
  height: 240px;
  border-radius: 20px;
  overflow: hidden;
  margin-top: 40px;
}
.swiperphone {
  width: 100%;
  height: 140px;
  border-radius: 20px;
  overflow: hidden;
  margin-top: 40px;
}
.swiper image,
.swiperphone image {
  width: 100%;
  height: 100%;
}

.activite {
  color: #db2940;
  border-bottom: 2px solid #db2940;
}
.transaction {
  background-color: #fff;
  border-radius: 10px;
  margin-top: 20px;
}
.scroll-div_H {
  white-space: nowrap;
  width: 100%;
  color: #b9b9b9;
  border-bottom: 2px solid #eee;
  height: 44px;
}

.scroll-div-item_H {
  display: inline-block;
  padding: 10px 0px;
  text-align: center;
  font-size: 16px;
  margin: 0 40px;
  cursor: pointer;
}
.swiper_item {
  padding: 30px 0px;
  margin-bottom: 20px;
}
.search {
  display: flex;
  margin-bottom: 20px;
  align-items: center;
}
.uni-form-item {
  display: flex;
  color: #67676c;
  margin: 0 10px;
  font-size: 14px;
  align-items: center;
  span {
    white-space: nowrap;
  }
}
.uni-input {
  border: 2px solid #e4e4e4;
  border-radius: 10px;
  padding: 10px 10px;
  width: 200px;
}
/deep/.uni-select__input-placeholder[data-v-6b64008e] {
  color: #e4e4e4 !important;
}
.line {
  width: 40px;
  height: 2px;
  background-color: #e4e4e4;
  margin: 0px 10px;
}

.th {
  background-color: #f5f5f5;
}
button::after {
  background: none;
}
.seedetails {
  color: #fff;
  background: linear-gradient(#d82141, #f36638);
  font-size: 12px;
  box-sizing: border-box;
  padding: 6px 15px;
  line-height: normal;
}
.uni-pagination {
  margin-top: 80px;
}
/deep/.page--active {
  background: linear-gradient(#d82141, #f36638) !important;
}
.uni-stat__select[data-v-6b64008e] {
  width: 270px;
}
/deep/.uni-popup__wrapper {
  border-radius: 20px !important;
}

.trading-title {
  text-align: center;
  font-size: 20px;
  margin: 20px 0;
}
.trading-particulars {
  display: flex;
  border-bottom: 1px dashed #dfdfdf;
  padding: 15px 0;
  font-size: 12px;
}
.last-particulars {
  border: none;
}
.charactername {
  width: 33%;
  border-right: 1px dashed #dfdfdf;
  text-align: center;
  div {
    color: #999;
    margin-bottom: 10px;
  }
}
.charactername:last-child {
  border: none;
}
.role-information {
  width: 33%;
  padding: 0px 10px;
  // text-align: center;
}
.information {
  margin: 15px 0;
}
.information span:first-child {
  color: #999;
}
.tradingbuy {
  display: flex;
  margin-top: 40px;
  div {
    flex: 1;
    margin: 0px 20px;
    border-radius: 5px;
    height: 48px;
    text-align: center;
    line-height: 48px;
    cursor: pointer;
  }
}
.buynow {
  color: #fff;
  background: linear-gradient(#d82141, #f36638);
}
.buynow:hover {
  background: linear-gradient(#e15b71, #fbbda9);
}
.cancel {
  color: #d82241;
  background: #fff9f8;
  border: 1px solid #d82241;
}
.cancel:hover {
  background: #ffebe8;
}
.mb80 {
  margin-bottom: 70px;
}
</style>
